package main

import (
	"fmt"
	// "manygo/dohttp"
	"manygo/mytools"
	// "manygo/rabbitmq"
	"strings"
	// "time"
	"bufio"
	"os"
)

var tongzhi chan int

//tt 132
func tt(s, e int, aaa []string, sn int) {
	n := 1
	f, err := os.Create(`C:\Users\lixuecheng\Desktop\tmp\mm1` + mytools.Int2String(sn) + ".txt")
	if err != nil {
		fmt.Printf("create map file error: %v\n", err)
		panic(err)
	}
	defer f.Close()
	w := bufio.NewWriter(f)
	for j := s; j < e; j++ {
		// time.Sleep(time.Millisecond * 2)
		ss := ""
		if j%100000 == 0 {
			fmt.Println(j)
		}
		for _, x := range aaa {
			if x == "账单编号" {
				ss += "账单编号" + mytools.Int2String(sn) + ","
			} else if x == "雇员编号" {
				ss += "雇员编号" + mytools.Int2String(n) + ","
				n++
				if n > 6000 {
					n = 1
				}

			} else if x == "所属月" {
				ss += "202004" + ","
			} else if x == "账单公司编号" {
				ss += "公司编号" + mytools.Int2String(n/61+1) + ","
			} else if strings.HasPrefix(x, "金额") {
				ss += mytools.Int2String((n+j)/100+1) + ","
			} else {
				ss += x + ","
			}

		}
		bb := []byte(ss)
		bb = bb[:len(bb)-1]
		// rmq.PublishSimple(bb)
		fmt.Fprintln(w, string(bb))
	}
	w.Flush()
	tongzhi <- 1
}

func main() {
	tongzhi = make(chan int)
	// v := mytools.MyInput("起始的数字：")
	// v2 := mytools.MyInput("结束的数字：")
	// i, err := mytools.String2Int(v)
	// if err != nil {
	// 	panic(err)
	// }
	// i2, err2 := mytools.String2Int(v2)
	// if err2 != nil {
	// 	panic(err)
	// }
	i := 1
	i2 := 5000001
	aa := "账单编号,雇员编号,公司编号,所属月,雇员姓名,付款类型,账单公司编号,委托机构,城市,核销状态,核销时间,金额1,金额2,金额3,金额4,金额5,金额6,金额7,金额8,金额9,金额10,金额11,金额12,金额13,金额14,金额15,金额16,金额17,金额18,金额19,金额20,金额21,金额22,金额23,金额24,金额25"
	// rmq := rabbitmq.NewRabbitMQSimple("mqshoufu", "admin", "admin", "192.168.56.115", "5672", "/")
	aaa := strings.Split(aa, ",")
	c := i2 - i
	for s := 0; s < 10; s++ {
		go tt(i+c*s/10, i+c*(s+1)/10, aaa, s)
	}
	ttt := 0
	for x := range tongzhi {
		ttt += x
		if ttt == 10 {
			break
		}
	}

}
